<?php

/**
 * @file
 * Contains \Drupal\gdlisnet\Plugin\QueueWorker\NotifyOverdue.
 */

namespace Drupal\gdlisnet\Plugin\QueueWorker;

use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\qyweixin\MessageBase;

/**
 * Notify Readers that are overdued.
 *
 * @QueueWorker(
 *   id = "gdlisnet.overdue",
 *   cron = {"time" = 60}
 * )
 */
class NotifyOverdue extends QueueWorkerBase {

  /**
   * {@inheritdoc}
   */
  public function processItem($reader_info) {
	$reader=$reader_info->readerid;
	$data=$reader_info->data;
	
	$p=\Drupal::service('plugin.manager.qyweixin.agent')->createInstance('library');
	foreach($data as $d) {
		try {
			$msg=new MessageBase();
			$msg->setMsgType(MessageBase::MESSAGE_TYPE_TEXT)->setContent($d)->setToUser($reader);
			$p->messageSend($msg);
		} catch(\Exception $e) {
			var_dump($e->getMessage());
		}
	}
  }
}
?>
